<!--  -->
<template>
  <el-container>
    <el-header
      >Header
      <button @click="fun()">退出</button>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          default-active="1"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <router-link
            :to="v.meta.linkto"
            v-for="(v, i) in this.$router.options.routes[2].children"
            :key="i"
          >
            <el-menu-item :index="i.toString()">
              <i :class="v.meta.linkicon"></i>
              <span slot="title">{{ v.meta.linktext }}</span>
            </el-menu-item>
          </router-link>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import { loginlink } from "@/api/loginapi.js";
export default {
  components: {},
  data() {
    return {};
  },
  computed: {},
  watch: {},
  methods: {
    fun() {
        window.localStorage.removeItem("token");
        // this.$nextTick(this.$router.push("./"));  
        this.$router.go(0)
    },
  },
  created() {
  //  console.log(window.localStorage.getItem("token"));
    if (window.localStorage.getItem("token") == null) {
      alert("你没有登录，先登录");
      this.$router.push("/");
    } else {
      let usp = new URLSearchParams();
      usp.append("usertoken", window.localStorage.getItem("token"));
      loginlink("/api/useertoken", usp).then((ok) => {
        // console.log(ok);
        if (ok.data.data.loginok == 1) {
          // alert("欢迎进入");
          // console.log("登录成功");
        } else {
          alert("你没有登录，先登录");
          this.$router.push("/"); 
        }
      });
    }
  },
  mounted(){},
};
</script>
<style lang='less' scoped>
.el-header {
  background-color: pink;
}
.el-aside {
  background-color: gray;
  height: 100%;
}
.el-main {
  background-color: yellowgreen;
}
.el-container {
  height: 100%;
}
</style>